home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / socketx / CONNECTO.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-10-06  |  7.6 KB  |  252 lines

  1. VERSION 5.00
  2. Object = "{C7212F93-30E8-11D2-B450-0020AFD69DE6}#1.0#0"; "SocketX.OCX"
  3. Begin VB.Form Form1 
  4.    Caption         =   "Connect To Remote Server"
  5.    ClientHeight    =   5400
  6.    ClientLeft      =   1140
  7.    ClientTop       =   1515
  8.    ClientWidth     =   9480
  9.    LinkTopic       =   "Form1"
  10.    PaletteMode     =   1  'UseZOrder
  11.    ScaleHeight     =   5400
  12.    ScaleWidth      =   9480
  13.    Begin SocketXCtl.SocketXCtl SocketX 
  14.       Left            =   1440
  15.       Top             =   4440
  16.       _cx             =   847
  17.       _cy             =   847
  18.       AcceptTimeout   =   0
  19.       BlockingMode    =   -842150451
  20.       Blocking        =   -1  'True
  21.       BroadcastEnabled=   -1  'True
  22.       ConnectTimeout  =   0
  23.       EventMask       =   63
  24.       KeepAliveEnabled=   0   'False
  25.       LibraryName     =   "WSOCK32.DLL"
  26.       LingerEnabled   =   0   'False
  27.       LingerMode      =   0
  28.       LingerTime      =   0
  29.       LocalAddress    =   ""
  30.       LocalPort       =   0
  31.       OutOfBandEnabled=   0   'False
  32.       ReceiveBufferSize=   8192
  33.       ReceiveTimeout  =   0
  34.       RemoteAddress   =   ""
  35.       RemoteName      =   ""
  36.       ReuseAddressEnabled=   0   'False
  37.       RemotePort      =   0
  38.       RouteEnabled    =   -1  'True
  39.       SendTimeout     =   0
  40.       SendBufferSize  =   8192
  41.       SocketType      =   0
  42.       TcpNoDelayEnabled=   0   'False
  43.    End
  44.    Begin VB.ListBox List2 
  45.       Height          =   3375
  46.       Left            =   5760
  47.       TabIndex        =   12
  48.       Top             =   1800
  49.       Width           =   3495
  50.    End
  51.    Begin VB.CheckBox Check1 
  52.       Caption         =   "Blocking"
  53.       Height          =   375
  54.       Left            =   120
  55.       TabIndex        =   9
  56.       Top             =   3840
  57.       Width           =   1095
  58.    End
  59.    Begin VB.TextBox Text1 
  60.       Height          =   285
  61.       Left            =   840
  62.       TabIndex        =   6
  63.       Text            =   "Text1"
  64.       Top             =   3000
  65.       Width           =   375
  66.    End
  67.    Begin VB.CommandButton Command1 
  68.       Caption         =   "Connect"
  69.       Height          =   375
  70.       Left            =   120
  71.       TabIndex        =   1
  72.       Top             =   4560
  73.       Width           =   1095
  74.    End
  75.    Begin VB.ListBox List1 
  76.       Height          =   840
  77.       Left            =   120
  78.       TabIndex        =   0
  79.       Top             =   1560
  80.       Width           =   2295
  81.    End
  82.    Begin VB.Line Line2 
  83.       BorderColor     =   &H80000010&
  84.       X1              =   0
  85.       X2              =   9480
  86.       Y1              =   1320
  87.       Y2              =   1320
  88.    End
  89.    Begin VB.Line Line1 
  90.       BorderColor     =   &H80000010&
  91.       X1              =   5640
  92.       X2              =   5640
  93.       Y1              =   1320
  94.       Y2              =   5400
  95.    End
  96.    Begin VB.Label Label8 
  97.       Caption         =   "Trace Messages:"
  98.       Height          =   255
  99.       Left            =   5760
  100.       TabIndex        =   11
  101.       Top             =   1560
  102.       Width           =   1455
  103.    End
  104.    Begin VB.Label Label7 
  105.       BeginProperty Font 
  106.          Name            =   "MS Sans Serif"
  107.          Size            =   12
  108.          Charset         =   0
  109.          Weight          =   400
  110.          Underline       =   0   'False
  111.          Italic          =   0   'False
  112.          Strikethrough   =   0   'False
  113.       EndProperty
  114.       Height          =   1095
  115.       Left            =   0
  116.       TabIndex        =   10
  117.       Top             =   120
  118.       Width           =   9255
  119.    End
  120.    Begin VB.Label Label6 
  121.       Caption         =   "You can run this sample in either blocking or non-blocking mode."
  122.       Height          =   495
  123.       Left            =   2640
  124.       TabIndex        =   8
  125.       Top             =   3840
  126.       Width           =   2775
  127.    End
  128.    Begin VB.Label Label5 
  129.       Caption         =   "When an address is displayed try connecting using the Connect button."
  130.       Height          =   615
  131.       Left            =   2640
  132.       TabIndex        =   7
  133.       Top             =   4560
  134.       Width           =   2775
  135.    End
  136.    Begin VB.Label Label4 
  137.       Caption         =   "Timeout:"
  138.       Height          =   255
  139.       Left            =   120
  140.       TabIndex        =   5
  141.       Top             =   3000
  142.       Width           =   615
  143.    End
  144.    Begin VB.Label Label3 
  145.       Caption         =   "Host Not Found"
  146.       Height          =   255
  147.       Left            =   120
  148.       TabIndex        =   4
  149.       Top             =   2520
  150.       Width           =   2055
  151.    End
  152.    Begin VB.Label Label2 
  153.       Caption         =   "You may change the timeout if you choose. Timeouts are specified in seconds."
  154.       Height          =   615
  155.       Left            =   2640
  156.       TabIndex        =   3
  157.       Top             =   2880
  158.       Width           =   2775
  159.    End
  160.    Begin VB.Label Label1 
  161.       Caption         =   "Choose a server from the list.  If the server's address can be found it will be displayed just below the list.  "
  162.       Height          =   735
  163.       Left            =   2640
  164.       TabIndex        =   2
  165.       Top             =   1560
  166.       Width           =   2775
  167.    End
  168. Attribute VB_Name = "Form1"
  169. Attribute VB_GlobalNameSpace = False
  170. Attribute VB_Creatable = False
  171. Attribute VB_PredeclaredId = True
  172. Attribute VB_Exposed = False
  173. Private Sub Trace(s As String)
  174.     If (List2.ListCount > 100) Then
  175.         List2.RemoveItem 0
  176.     End If
  177.     List2.AddItem s
  178.     List2.TopIndex = List2.NewIndex
  179. End Sub
  180. Private Sub Command1_Click()
  181.     SocketX.ConnectTimeout = CInt(Text1.Text)
  182.     SocketX.Blocking = Check1.Value
  183.     On Error Resume Next
  184.     Screen.MousePointer = 11
  185.     SocketX.Connect , 21
  186.     Screen.MousePointer = 0
  187. End Sub
  188. Private Sub Form_Load()
  189.     Me.Show
  190.     List1.AddItem "ftp.mabry.com"
  191.     List1.AddItem "enews.newsguy.com"
  192.     List1.AddItem "www.mabry.com"
  193.     List1.AddItem "always.fails.com"
  194.     Text1.Text = SocketX.ConnectTimeout
  195.     SocketX.Blocking = True
  196.     SocketX.BlockingMode = soxPseudoBlocking
  197.     Check1.Value = 1
  198.     SocketX.Create
  199.     DoEvents
  200.     List1.ListIndex = 0
  201. End Sub
  202. Private Sub List1_Click()
  203.     '
  204.     ' Enable name/address translation
  205.     '
  206.     Screen.MousePointer = 11
  207.     Command1.Enabled = False
  208.     Trace "Starting address lookup"
  209.     SocketX.RemoteNameAddrXlate = True
  210.     Label3.Caption = "Looking up address"
  211.     DoEvents
  212.     SocketX.RemoteName = List1.List(List1.ListIndex)
  213.     Trace "Address lookup complete"
  214.     If (SocketX.RemoteAddress = "") Then
  215.         Label3.Caption = "Host Not Found"
  216.     Else
  217.         Label3.Caption = SocketX.RemoteAddress
  218.     End If
  219.     Command1.Enabled = True
  220.     Screen.MousePointer = 0
  221. End Sub
  222. Private Sub SocketX_Done(ByVal LastMethod As SocketXCtl.MethodsEnum, ByVal ErrorCode As Integer)
  223.     Trace "Done( " & LastMethod & ", " & ErrorCode & ")"
  224.     Select Case (LastMethod)
  225.         Case soxConnect
  226.             Trace "Connect"
  227.             If (SocketX.Blocking = True) Then
  228.                 SocketX_Connect ErrorCode
  229.             End If
  230.         Case soxClose
  231.             Trace "Close"
  232.         Case soxCreate
  233.             Trace "Create"
  234.     End Select
  235. End Sub
  236. Private Sub SocketX_Connect(ByVal ErrorCode As Integer)
  237.     Trace "Connect(" & ErrorCode & ")"
  238.     '
  239.     ' Connect finished, let's see what happened
  240.     '
  241.     If (ErrorCode) Then
  242.         Trace "Connect failed: " & ErrorCode
  243.     Else
  244.         Trace "Connected!"
  245.     End If
  246.     '
  247.     ' Close socket and recreate for next try.
  248.     '
  249.     SocketX.Close
  250.     SocketX.Create
  251. End Sub
  252.